home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 30 / Mac Magazin and MacEasy Magazine CD - Issue 30.iso / utilities / Mac OS X / Flurry / Flurry source / Source Folder / Star.cpp < prev    next >
C/C++ Source or Header  |  2001-04-17  |  3KB  |  136 lines

  1. // Star.cpp: implementation of the Star class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5. #include "std.h"
  6. #include "Star.h"
  7.  
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11.  
  12. Star::Star()
  13. {
  14.     mystery = 0.0f;//2323.2323f;
  15. }
  16.  
  17. Star::~Star()
  18. {
  19.  
  20. }
  21.  
  22. void Star::Draw()
  23. {
  24.     return;
  25.     float width,sx,sy;
  26.     float w,z;
  27.  
  28.     if (ate == false)
  29.         return;
  30.  
  31.     width = 50000.0f * sys_glWidth / 1024.0f;
  32.     
  33.     z = position[2];
  34.     sx = position[0] * sys_glWidth / z + sys_glWidth * 0.5f;
  35.     sy = position[1] * sys_glWidth / z + sys_glHeight * 0.5f;
  36.     w = width*4.0f / z;
  37.  
  38.     float screenx = sx;
  39.     float screeny = sy;
  40.     
  41.     const float black[4] = {0.0f,0.0f,0.0f,1.0f};
  42.     
  43.     glPushMatrix();
  44.     glTranslatef(screenx,screeny,0.0f);
  45.     float scale = w/100.0f;
  46.     glScalef(scale,scale,0.0f);
  47.     float a;
  48.     float c = 0.08f;
  49.     float r,g,b;
  50.     for (int k=0;k<30;k++)
  51.     {
  52.         a = ((float) (rand() % 3600)) / 10.0f;
  53.         glRotatef(a,0.0f,0.0f,1.0f);
  54.         glBegin(GL_QUAD_STRIP);
  55.         glColor4fv(black);
  56.         glVertex2f(-3.0f,0.0f);
  57.         a = 3.0f + (float) (rand() & 2047) * c;
  58.         glVertex2f(-3.0f,a);
  59.         r = 0.125f + (float) (rand() % 875) / 1000.0f;
  60.         g = 0.125f + (float) (rand() % 875) / 1000.0f;
  61.         b = 0.125f + (float) (rand() % 875) / 1000.0f;
  62.         glColor4f(r,g,b,1.0f);
  63.         glVertex2f(0.0f,0.0f);
  64.         glColor4fv(black);
  65.         glVertex2f(0.0f,a);
  66.         glVertex2f(3.0f,0.0f);
  67.         glVertex2f(3.0f,a);
  68.         glEnd();
  69.     }
  70.     glPopMatrix();
  71. }
  72.  
  73. #define BIGMYSTERY 1800.0
  74. #define MAXANGLES 16384
  75.  
  76. void Star::Update()
  77. {
  78.     const float rotationsPerSecond = (float) (2.0*PI*TICKSPERSECOND/MAXANGLES) * 0.5f /* speed control */;
  79.     double thisPointInRadians;
  80.     double thisAngle = fTime*rotationsPerSecond;
  81.     float cf;
  82.     int i;
  83.     double tmpX1,tmpY1,tmpZ1;
  84.     double tmpX2,tmpY2,tmpZ2;
  85.     double tmpX3,tmpY3,tmpZ3;
  86.     double tmpX4,tmpY4,tmpZ4;
  87.     double rotation;
  88.     double cr;
  89.     double sr;
  90. //    float mystery = 2323.2323f;
  91.     
  92.     float old[3];
  93.  
  94.     ate = false;
  95.     for (i=0;i<3;i++)
  96.     {
  97.         old[i] = position[i];
  98.     }
  99.     
  100.     cf = ((float) (cos(7.0*((fTime)*rotationsPerSecond))+cos(3.0*((fTime)*rotationsPerSecond))+cos(13.0*((fTime)*rotationsPerSecond))));
  101.     cf /= 6.0f;
  102.     cf += 0.75f; // 0.25 - 1.25
  103.     thisPointInRadians = 2.0 * PI * (double) mystery / (double) BIGMYSTERY;
  104.     
  105.     position[0] = 250.0f * cf * (float) cos(11.0 * (thisPointInRadians + (3.0*thisAngle)));
  106.     position[1] = 250.0f * cf * (float) sin(12.0 * (thisPointInRadians + (4.0*thisAngle)));
  107.     position[2] = 250.0f * (float) cos((23.0 * (thisPointInRadians + (12.0*thisAngle))));
  108.     
  109.     rotation = thisAngle*0.501 + 5.01 * (double) mystery / (double) BIGMYSTERY;
  110.     cr = cos(rotation);
  111.     sr = sin(rotation);
  112.     tmpX1 = position[0] * cr - position[1] * sr;
  113.     tmpY1 = position[1] * cr + position[0] * sr;
  114.     tmpZ1 = position[2];
  115.     
  116.     tmpX2 = tmpX1 * cr - tmpZ1 * sr;
  117.     tmpY2 = tmpY1;
  118.     tmpZ2 = tmpZ1 * cr + tmpX1 * sr;
  119.     
  120.     tmpX3 = tmpX2;
  121.     tmpY3 = tmpY2 * cr - tmpZ2 * sr;
  122.     tmpZ3 = tmpZ2 * cr + tmpY2 * sr + seraphDistance;
  123.     
  124.     rotation = thisAngle*2.501 + 85.01 * (double) mystery / (double) BIGMYSTERY;
  125.     cr = cos(rotation);
  126.     sr = sin(rotation);
  127.     tmpX4 = tmpX3 * cr - tmpY3 * sr;
  128.     tmpY4 = tmpY3 * cr + tmpX3 * sr;
  129.     tmpZ4 = tmpZ3;
  130.     
  131.     position[0] = (float) tmpX4;
  132.     position[1] = (float) tmpY4;
  133.     position[2] = (float) tmpZ4;
  134.  
  135. }
  136.